package cn.blb.service.oss.controller;


import cn.blb.service.oss.service.FileService;
import cn.yl.api.server.result.Result;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/oss")
public class FileController {
    private final FileService fileService;

    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    @PostMapping("/upload/{path}")
    public Result upload(MultipartFile file, @PathVariable String path){
        if(file==null){
            System.out.println("未上传");
            return Result.ok().setData("url",null);
        }
        String upload = fileService.upload(file,path);
        return Result.ok().setData("item",upload);
    }
}
